#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

void main()
{
	int fd1 = open("1.txt",O_RDONLY);

	struct flock ltype;
	ltype.l_type = F_RDLCK;
	ltype.l_start = 0;
	ltype.l_whence = SEEK_SET;
	ltype.l_len = 0;

	printf("start rdlck\n");
	while(1)
	{	printf("try rdlck\n");		
		int rec = fcntl(fd1,F_SETLK,&ltype);
		if (rec == 0)
			break;
		sleep(1);
	}
	printf("rdlck success\n");
	getchar();

	ltype.l_type = F_UNLCK;
	fcntl(fd1,F_SETLK,ltype);
	printf("unlock rdlocd\n");

	close(fd1);

}